/***************************************************
 @Name :        小铭同学
 @Time :        2022-10-30
 @Email :       LiaoMingWJ233@163.com
 @Comment :     系统用到的uart配置
 @FileName :    dma.c
 @Version :     1.0
****************************************************/


#include "dma.h"

#include "status.h"

extern TIM_HandleTypeDef htim2;

DMA_HandleTypeDef hdma_tim2_ch1_trig, hdma_tim2_ch2_trig;

void dma_init(void)
{
  __HAL_RCC_DMA1_CLK_ENABLE();
  
    TIM_HandleTypeDef htim = htim2;
    /* TIM5 DMA Init */
    /* TIM5_CH1_TRIG Init */
    hdma_tim2_ch1_trig.Instance = DMA1_Channel5;
    hdma_tim2_ch1_trig.Init.Direction = DMA_MEMORY_TO_PERIPH;
    hdma_tim2_ch1_trig.Init.PeriphInc = DMA_PINC_DISABLE;
    hdma_tim2_ch1_trig.Init.MemInc = DMA_MINC_ENABLE;
    hdma_tim2_ch1_trig.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
    hdma_tim2_ch1_trig.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
    hdma_tim2_ch1_trig.Init.Mode = DMA_NORMAL;
    hdma_tim2_ch1_trig.Init.Priority = DMA_PRIORITY_MEDIUM;
    HAL_DMA_Init(&hdma_tim2_ch1_trig);

    /* TIM5 DMA Init */
    /* TIM5_CH2_TRIG Init */
    hdma_tim2_ch2_trig.Instance = DMA1_Channel7;
    hdma_tim2_ch2_trig.Init.Direction = DMA_MEMORY_TO_PERIPH;
    hdma_tim2_ch2_trig.Init.PeriphInc = DMA_PINC_DISABLE;
    hdma_tim2_ch2_trig.Init.MemInc = DMA_MINC_ENABLE;
    hdma_tim2_ch2_trig.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
    hdma_tim2_ch2_trig.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
    hdma_tim2_ch2_trig.Init.Mode = DMA_NORMAL;
    hdma_tim2_ch2_trig.Init.Priority = DMA_PRIORITY_MEDIUM;
    HAL_DMA_Init(&hdma_tim2_ch2_trig);
		
    /* Several peripheral DMA handle pointers point to the same DMA handle.
     Be aware that there is only one stream to perform all the requested DMAs. */
    __HAL_LINKDMA(htim,hdma[TIM_DMA_ID_CC1],hdma_tim2_ch1_trig);
    __HAL_LINKDMA(htim,hdma[TIM_DMA_ID_TRIGGER],hdma_tim2_ch1_trig);

		__HAL_LINKDMA(htim,hdma[TIM_DMA_ID_CC2],hdma_tim2_ch2_trig);
    __HAL_LINKDMA(htim,hdma[TIM_DMA_ID_TRIGGER],hdma_tim2_ch2_trig);

    /* TIM3 interrupt Init */
    HAL_NVIC_SetPriority(TIM2_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(TIM2_IRQn);
    
    /* DMA interrupt init */
    /* DMA1_Stream4_IRQn interrupt configuration */
     HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn);
		HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(DMA1_Channel7_IRQn);


}







